package com.lovecanon.jzjl.web;

import org.apache.poi.ss.usermodel.Workbook;

import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.OutputStream;

import static org.springframework.util.ObjectUtils.isEmpty;

public class BaseController {
    public static final String SUCCESS = "提交成功";
    public static final String ERROR = "提交失败";



    protected void exportExl(String fileName, Workbook wb, HttpServletResponse response) {


        try {

            if(isEmpty(fileName)) fileName = "报表";

            fileName = java.net.URLEncoder.encode(fileName, "UTF-8");

            response.setContentType("application/vnd.ms-excel");
            response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");

            OutputStream ouputStream = response.getOutputStream();
            wb.write(ouputStream);

            ouputStream.flush();
            ouputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
